//
//  LYTabBarViewController.m
//  IPhoneX适配
//
//  Created by 训网高 on 2018/4/28.
//  Copyright © 2018年 训网高. All rights reserved.
//

#import "LYTabBarViewController.h"
//首页
#import "FirstViewController.h"
//分类
#import "SecondViewController.h"
//工具
#import "ThirdViewController.h"
//我的
#import "FourthViewController.h"
@interface LYTabBarViewController ()

@end

@implementation LYTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.tabBar.barTintColor = [UIColor clearColor];  //tabbar的背景颜色
    self.tabBar.tintColor = [UIColor purpleColor]; //tabbarItem选中时的颜色，可以根据需要进行修改
    [self setUpChildViewControllers];
}

- (void)setUpChildViewControllers {
    NSArray *titleNames = @[@"首页",@"分类",@"工具",@"我的"];
    NSArray *imageNameArray = @[@"shouye",@"xiaoxino",@"faxianno",@"wodeno"];
    NSArray *selectImageNameArray = @[@"shouyeselected",@"xiaoxiselected",@"faxianselected",@"wodeselected"];
    FirstViewController *first = [[FirstViewController alloc] init];
    [self addChildViewController:first withTitle:titleNames[0] withImage:imageNameArray[0] WithSelectImage:selectImageNameArray[0]];
    //分类
    SecondViewController *second = [[SecondViewController alloc] init];
    [self addChildViewController:second withTitle:titleNames[1] withImage:imageNameArray[1] WithSelectImage:selectImageNameArray[1]];
    //工具
    ThirdViewController *third = [[ThirdViewController alloc] init];
    [self addChildViewController:third withTitle:titleNames[2] withImage:imageNameArray[2] WithSelectImage:selectImageNameArray[2]];
    //我的
    FourthViewController *fourth = [[FourthViewController alloc] init];
    [self addChildViewController:fourth withTitle:titleNames[3] withImage:imageNameArray[3] WithSelectImage:selectImageNameArray[3]];
}

- (void)addChildViewController:(UIViewController*)childController withTitle:(NSString *)title withImage:(NSString *)imageName WithSelectImage:(NSString *)selectImageName {
    childController.tabBarItem.title = title;
//    childController.tabBarController.tabBar.barTintColor = [UIColor redColor];
    childController.tabBarItem.image = [UIImage imageNamed:imageName];
    childController.tabBarItem.selectedImage = [UIImage imageNamed:selectImageName];
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:childController];
    
    [self addChildViewController:navi];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
